require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var vm = new Vue({
    el:"#deliverGoods",
    data:{
        name:"",
        type:"",
        isScreen:false,
        uid:"",
        orderNumber:"",
        express:"",
        expressNumber:"",
        address:{},
        expresLists:{}
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.uid=this.searchObject&&this.searchObject.uid;
        this.orderNumber=this.searchObject&&this.searchObject.orderNumber;
        this.type=this.searchObject&&this.searchObject.type;
        if(this.type==1){  //发货
            this.name="发货";
            this.userOrderInfo();
        }else{
            this.name="填写物流";
        }
        this.expresList();
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //订单详情
        userOrderInfo:function(){
            var that=this;
            var data={
                loginUid:that.uid,
                orderNumber:that.orderNumber
            };
            that.ajax({url:"/purchase/userOrderInfo",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.address=b.json.data.address;
                }else{
                    vm.$refs.prompt.toast("获取订单详情失败！");
                }
            });
        },
        //快递公司
        expresList:function(){
            var that=this;
            var data={
                loginUid:that.uid
            };
            that.ajax({url:"/happyi/expresList",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.expresLists=b.json.data;
                }else{
                    vm.$refs.prompt.toast("获取快递公司失败！");
                }
            });
        },
        getIsScreen:function(){
            this.isScreen=!this.isScreen;
        },
        //选择快递
        getExpress:function(name){
            this.express=name;
            this.getIsScreen();
        },
        //发货
        sellerOrderDeliver:function(){
            var that=this;
            if(!that.expressNumber){
                vm.$refs.prompt.toast("请输入快递单号！");
                return false;
            }
            if(!that.express){
                vm.$refs.prompt.toast("请选择快递！");
                return false;
            }
            var data={
                loginUid:that.uid,
                orderNumber:that.orderNumber,
                courier:that.express,
                courierNumber:that.expressNumber
            };
            console.log(data)
            that.ajax({url:"/happyi/sellerOrderDeliver",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    that.getBack();
                    // that.address=b.json.data.address;
                }else{
                    vm.$refs.prompt.toast("提交失败！");
                }
            });
        },
        //填写物流
        returnLogistics:function(){
            var that=this;
            if(!that.expressNumber){
                vm.$refs.prompt.toast("请输入快递单号！");
                return false;
            }
            if(!that.express){
                vm.$refs.prompt.toast("请选择快递！");
                return false;
            }
            var data={
                loginUid:that.uid,
                orderNumber:that.orderNumber,
                express:that.express,
                expressNumber:that.expressNumber
            };
            console.log(data)
            that.ajax({url:"/purchase/returnLogistics",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    that.getBack();
                    // that.address=b.json.data.address;
                }else{
                    vm.$refs.prompt.toast("发货失败！");
                }
            });
        },
        getNext:function(num){
            if(num==1){
                location.href="/addAddress?type=3&uid="+this.uid+"&addressId="+this.address.addressId+"&orderNumber="+this.orderNumber;
            }
        }
    }
});